package com.laborer.controller;

import java.util.List;

import com.laborer.entity.User;
import com.laborer.model.result.Result;
import com.laborer.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 用户
 * @Author: jeecg-boot
 * @Date:   2021-06-08
 * @Version: V1.0
 */
@Controller
@RequestMapping("/user")
@Slf4j
@SessionAttributes("userId")
public class UserController{
	private final String PREFIX = "assignmentIndex";
	@Autowired
	private IUserService userService;

	@RequestMapping("")
	public String index(){
		return PREFIX + "/assignmentIndex";
	}

	@PostMapping("/login")
	@ResponseBody
	public Result login(User user, Model model){
		Result result=new Result();
		boolean login = userService.login(user);
		if(login){
			result.success(null, 10 ,1);
			model.addAttribute("userId","user");
			return result;
		}
		result.error("账号或密码错误");
		return result;
	}
}
